package cn.demengsite.service;

import cn.demengsite.base.LB_ProductConfig;
import cn.demengsite.model.BaseInfo;
import cn.demengsite.model.DTO.ImportProductDTO;
import cn.demengsite.model.Product;
import cn.demengsite.utils.LB_ProductUtils;
import cn.demengsite.utils.ProductUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static cn.demengsite.base.ProductConfig.productColorMap;
import static cn.demengsite.base.ProductConfig.productSizeMap;

@Service
public interface InventoryService {
    BaseInfo getAllProduct();

    BaseInfo getAllProductGroupByProductId();

    BaseInfo getAllProductByType(String typeCode);

    BaseInfo insertProduct(List<Product> products);

    BaseInfo updateProduct(Product product);

    BaseInfo updateProductByProductId(Product product);

    BaseInfo updateProductImage(String productId,int attrType,String attrUrl );

    BaseInfo setSalePrice(String  styleCode ,int saleType );


    default List<Product> getProducts(ImportProductDTO productDTO){

        List<Product> products = new ArrayList<>();
        Product product = productDTO.getProduct();
        if(product.getProductId().startsWith("6")||product.getProductId().startsWith("3")){
            //是德蒙的货
            int countFlag = 0;
            if((productDTO.getSizes() ==null || productDTO.getSizes().size()==0)){
                //没有从下面选单独的码号，用的上面的大选
                countFlag = product.getSizeType()==1?4:6;
                for (int i = 0; i < countFlag; i++) {
                    Product product1 = new Product();
                    product1.setProductId(product.getProductId());
                    product1.setColorCode(product.getColorCode());
                    String sizeCode  = "00"+(i+1);
                    if(countFlag==4){
                        sizeCode  = "00"+(i+1);
                    }else {
                        sizeCode  = "00"+(i+4);
                    }
                    product1.setSizeCode(sizeCode);
                    product1.setProductNum(1);
                    product1.setOriginalPrice(product.getOriginalPrice());
                    product1.setColorName(productColorMap.get(product.getColorCode()));
                    product1.setSizeName(productSizeMap.get(sizeCode));
                    product1.setProductName(ProductUtils.getProductNameByProductId(product.getProductId()));

                    products.add(product1);
                }

            }else {
                //从下面选的单独的码号
                for (String sizeCode : productDTO.getSizes()) {
                    Product product1 = new Product();
                    product1.setProductId(product.getProductId());
                    product1.setColorCode(product.getColorCode());
                    product1.setSizeCode("0"+sizeCode);
                    product1.setColorName(productColorMap.get(product.getColorCode()));
                    product1.setSizeName(productSizeMap.get("0"+sizeCode));
                    product1.setProductName(ProductUtils.getProductNameByProductId(product.getProductId()));

                    product1.setProductNum(1);
                    product1.setOriginalPrice(product.getOriginalPrice());
                    products.add(product1);
                }
            }

        }else {
            //是LightBlue 的货,LightBlue 只有选号码入库
            for (String sizeCode : productDTO.getSizes()) {
                Product product1 = new Product();
                product1.setProductId(product.getProductId());
                product1.setColorCode(product.getColorCode());
                product1.setSizeCode(sizeCode);
                product1.setColorName(LB_ProductConfig.LBproductColorMap.get(product.getColorCode()));
                product1.setSizeName(LB_ProductConfig.LBproductSizeMap.get(sizeCode));
                product1.setProductName(LB_ProductUtils.getProductNameByProductId(product.getProductId()));
                product1.setProductNum(1);
                product1.setOriginalPrice(product.getOriginalPrice());
                products.add(product1);
            }

        }


        return products;
    }

}
